﻿<Controls:BorderLessWindow x:Class="MishraReader.Shell.MishraReaderWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:Controls="clr-namespace:MishraReader.Controls"        
        xmlns:Interop="clr-namespace:MishraReader.Interop"
        xmlns:System="clr-namespace:System;assembly=mscorlib" 
        xmlns:MishraReader="clr-namespace:MishraReader"
        xmlns:mr="http://mishrareader.codeplex.com/Reader"
                           xmlns:viewModels="clr-namespace:MishraReader.ViewModels;assembly=MishraReader.ViewModels"
                           xmlns:mishraReader="clr-namespace:MishraReader;assembly=MishraReader.ViewModels"
                           Title="Mishra Reader" 
        MinHeight="540" 
        MinWidth="800"
        Closing="Window_Closing"            
        StateChanged="Window_StateChanged"                                 
        WindowStartupLocation="CenterScreen"
        TextElement.FontSize="{StaticResource NormalTextSize}"
                           FocusManager.FocusedElement="{Binding ElementName=contentPart}"
        Style="{StaticResource MetroWindow}"
        x:Name="root" >

        

    <Window.Resources>
        <mr:UnreadCountToOverlayTextConverter x:Key="unreadCountToOverlayTextConverter" />
        <mr:UnreadCountToOverlayFontSizeConverter x:Key="unreadCountToOverlayFontSizeConverter" />
        <mr:BoolToTaskbarItemProgressStateConverter x:Key="boolToTaskbarItemProgressStateConverter" />
        <DataTemplate  DataType="{x:Type viewModels:ShareServiceJobViewModel}">
            <Border Background="{DynamicResource MetroAccentBrush}" Margin="0,0,0,5">
                <StackPanel Margin="30,1">
                    <TextBlock Text="{Binding Message}" 
                               Margin="0,5,0,3" 
                               Style="{StaticResource MetroSmallText}"  
                               Foreground="{StaticResource MetroFeatureContrastBrush}" />
                    <ProgressBar IsIndeterminate="True" Height="3" Foreground="{StaticResource MetroFeatureContrastBrush}" />
                </StackPanel>
            </Border>
        </DataTemplate>
        <DataTemplate x:Key="OverlayIcon" DataType="{x:Type System:Int32}">
            <Grid Width="16" Height="16" UseLayoutRounding="True"
                  TextOptions.TextFormattingMode="Display" x:Name="overlayGrid">
                <Ellipse 
                    Fill="{DynamicResource Windows7TaskbarOverlayIconBackground}"
                    StrokeThickness="0"
                    />
                <TextBlock x:Name="txtCount"
                    Foreground="White"
                    Text="{Binding Converter={StaticResource unreadCountToOverlayTextConverter}}"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    TextAlignment="Center"
                    FontWeight="Bold"
                    FontSize="12"
                    />
            </Grid>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Converter={StaticResource unreadCountToOverlayFontSizeConverter}}"
                             Value="Medium">
                    <Setter TargetName="txtCount" Property="FontSize" Value="10" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Converter={StaticResource unreadCountToOverlayFontSizeConverter}}"
                             Value="Large">
                    <Setter TargetName="txtCount" Property="FontSize" Value="14" />
                    <Setter TargetName="txtCount" Property="Margin" Value="1,-3,0,0" />
                </DataTrigger>
                <DataTrigger Binding="{Binding}" Value="0">
                    <Setter TargetName="overlayGrid" Property="Visibility" Value="Collapsed" />
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </Window.Resources>
    <Window.TaskbarItemInfo>
        <TaskbarItemInfo 
            MishraReader:TaskbarItemOverlay.Content="{Binding UnreadCount, ElementName=root}"
            MishraReader:TaskbarItemOverlay.Template="{StaticResource OverlayIcon}"
            ProgressState="{Binding IsSynchronizing, ElementName=root, Converter={StaticResource boolToTaskbarItemProgressStateConverter}}"
            />
    </Window.TaskbarItemInfo>        
    <Grid>
        <Interop:NotificationIcon x:Name="notificationIcon" 
                                  Icon="/MishraReader.ico" 
                                  Text="{x:Static mishraReader:Strings.MishraReader}" 
                                  MouseClick="notificationIcon_MouseClick" 
                                  Visibility="Collapsed"/>
        <ContentPresenter x:Name="contentPart" />

        <Grid IsHitTestVisible="False" VerticalAlignment="Top" HorizontalAlignment="Center">
            <mr:AnimatedItemsControl 
                ItemsSource="{Binding Events, ElementName=root}"
                StoryboardName="MetroFromTopFadeSlideFast" />
        </Grid>
    </Grid>
</Controls:BorderLessWindow>
